import { procedure, router } from '../trpc';
import { z } from 'zod';
import pageService from '@/service/page';
import markdownService from '@/service/markdown';

export const pageRouter = router({
    extractContents: procedure
        .input(z.object({
            url: z.string(),
            selector: z.string().optional(),
            simpleTag: z.boolean().optional()
        }))
        .query(async ({ input }) => {
            const { url } = input;
            const content = await pageService.extractContents(url!, {selector: '#content_views'});
            const parsedContent = markdownService.htmlToMd(content);
            return parsedContent;
        })
});